package fanshe.first.demo02;

/**
 * @author Mr.ma
 * @since 2022/10/27 15:33
 * 通过反射类创建对象，使用newInstance()方法
 *
 **/
public class Test02 {
    public static void main(String[] args) throws Exception {
        Class<Teacher> teacherClass = Teacher.class;
        Teacher teacher = teacherClass.newInstance();
        teacher.setName("张三");
        System.out.println("teacher = " + teacher);
    }
}
class Teacher{
    private String name;

    public Teacher() {
    }

    public Teacher(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
